package mo.offer_special;

public class L008 {

    public int minSubArrayLen(int target, int[] nums) {
        if (nums[0] >= target) {
            return 1;
        }

        int left = 0;
        int right = 0;
        int min = Integer.MAX_VALUE;
        int sum = 0;
        while (right < nums.length) {
            sum += nums[right];
            while (sum >= target && left <= right) {
                min = Math.min(min, right-left+1);
                sum -= nums[left];
                left++;
            }
            right++;
        }

        return min == Integer.MAX_VALUE ? 0 : min;
    }

    public static void main(String[] args) {
        L008 test = new L008();
        System.out.println(test.minSubArrayLen(7, new int[]{2,3,1,2,4,3}));
    }
}
